package com.easyCode.sqlMapper.renderHandler;

import com.easyCode.sqlMapper.mapInfo.TableMapInfo;
import com.easyCode.sqlMapper.template.RenderHandler;
import com.easyCode.sqlMapper.template.SqlTemplateConfig;
import com.easyCode.sqlMapper.template.TemplateContext;
import org.apache.velocity.VelocityContext;


/**
 * @author 大忽悠
 * @create 2022/12/3 19:41
 */
public class FactoryRenderHandler implements RenderHandler<VelocityContext> {
    @Override
    public String paramPrepare(VelocityContext velocityContext, TableMapInfo tableMapInfo, SqlTemplateConfig sqlTemplateConfig, TemplateContext templateContext) {
        velocityContext.put("packagePath", sqlTemplateConfig.getFactoryModuleName());
        velocityContext.put("className", tableMapInfo.getTableName());
        velocityContext.put("classNameDto", tableMapInfo.getTableName()+"Dto");
        velocityContext.put("primaryName", tableMapInfo.getPrimaryKeyName());
        velocityContext.put("daoModule", sqlTemplateConfig.getDaoModuleName());
        velocityContext.put("dtoModule", sqlTemplateConfig.getDtoModuleName());
        velocityContext.put("voModule", sqlTemplateConfig.getVoModuleName());

        templateContext.setVal(TemplateContext.JAVA_FILE_NAME,tableMapInfo.getTableName()+"Factory.java");

        return sqlTemplateConfig.getFactoryModuleName();
    }
}
